package com.example.service.impl;

import com.example.mapper.EmpMapper;
import com.example.mapper.StudnetMapper;
import com.example.pojo.GenderCount;
import com.example.pojo.JobOption;
import com.example.service.RepostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * RepostServiceImpl 类的描述信息
 *
 * @author 12427
 * @since 2025/6/7 10:01
 */
@Service
public class RepostServiceImpl implements RepostService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudnetMapper studnetMapper;

    /**
     * 获取对应职位的  分别多少人
     */
    @Override
    public JobOption getEmpJobData() {
//        1 调用mapper接口获取统计数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();
//        2.key和value  将获取的职位封装到
        List<Object> jobList = list.stream().map(maps -> maps.get("pos")).toList();
        List<Object> dataList = list.stream().map(maps -> maps.get("num")).toList();
//        然后封装到集合中
        return new JobOption(jobList, dataList);
    }

    /**
     * 统计  男性和女性 分别多少人
     * 这是封装到Map
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.getEmpGender();
    }


    @Override
    public List<Map<String, Object>> studentDegreeData() {
        List<Map<String, Object>> list = studnetMapper.studentDegreeData();
        List<Map<String, Object>> result = new ArrayList<>();
        for (Map<String, Object> map : list) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("name", map.get("name"));
            map1.put("value", map.get("value"));
            result.add(map1);
        }
        return result;
    }



    //  统计 每个科目人数
    @Override
    public Map<String, Object> getStudentCountData() {
        List<Map<String, Object>> rawData = studnetMapper.countStudentCountData();
        List<String> clazzList = new ArrayList<>();
        List<Number> dataList = new ArrayList<>();
        for (Map<String, Object> item : rawData) {
            clazzList.add((String) item.get("name"));
            dataList.add((Number) item.get("value"));
        }
        Map<String, Object> result = new HashMap<>();
        result.put("clazzList", clazzList);
        result.put("dataList", dataList);
        return result;
    }


    /**
     *  统计  男性和女性 分别多少人
     *   这是封装到对象中
     */
//    @Override
//    public List<GenderCount>  getEmpGenderData() {
//        return empMapper.getEmpGender();
//    }


}
